<!doctype html>
<html>
    
    <head>
        <meta charset="UTF-8">
        <meta name="Generator" content="EditPlus®">
        <meta name="Author" content="">
        <meta name="Keywords" content="">
        <meta name="Description" content="">
		<link rel="stylesheet" href="http://127.0.0.1/css/layui.css">
		<script src="http://127.0.0.1/js/jquery-1.10.2.min.js"></script>
		<script src="http://127.0.0.1/layui.js"></script>
        <title>优客服API Demo</title>
		<script language="javascript">
			var authorization ;
			var layer ;
			layui.use('layer', function(){
			  layer = layui.layer;
			});   
			var demo =  {
				login:function(username , password){
					$.post("http://127.0.0.1/tokens" , "username=admin&password=123456" , function(data){
						authorization = data ;
					}).error(function() { alert("error"); });
				},
				display:function(data){
					if(typeof data == 'string'){
						value = data ;
					}else{
						value = JSON.stringify(data)
					}
					layer.open({
					  type: 1,
					  area: ['800px', '500px'],
					  content: "<div style='width:100%;height:100%;overflow:hidden;'><textarea style='width:100%;height:100%;' readOnly='readOnly'>"+JSON.stringify(JSON.parse(value), null, 2)+"</textarea></div>" //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
					});	
				},
				ajax:function(url , callback){
					$.ajax({
						type: "get",
						url:url+"?authorization="+authorization , 
						headers:{"authorization":authorization},
						beforeSend: function(xhr) {
							xhr.setRequestHeader("authorization", authorization);

						 },
						success: function (data) {
							console.log(data);
							demo.display(data) ;
							
						}
					});

				},
				createWorkOrder:function(){
					var param = 'title=测试API创建工单';
					$.ajax({
						type: "PUT",
						url:"http://127.0.0.1/api/workorders" , 
						data: param,
						beforeSend: function(xhr) {
							 xhr.setRequestHeader("authorization", authorization);

						 },
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				createContacts:function(){
					var param = 'name=张天翼';
					$.ajax({
						type: "PUT",
						url:"http://127.0.0.1/api/contacts" , 
						data: param,
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				searchNamesList:function(){
					var param = '';
					$.ajax({
						type: "GET",
						url:"http://127.0.0.1/api/batch/search?id=402864816e79df69016e79e86b4000b9" , 
						headers:{"authorization":authorization},
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				createNamesList:function(){
					$.ajax({
						type: "POST",
						url:"http://127.0.0.1/api/batch/insert", 
						headers:{"authorization":authorization},
						contentType : 'application/json',
						dataType : 'json',
						type: "POST",
						data:JSON.stringify({'batid':'402864816e79df69016e79e86b4000b9','orgi':'ukewo','list':[{'电话':'199999999999999999','性别':"女"},{'电话':'19994444444444444',"性别":"南"}]}),
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				createContactsList:function(){
					$.ajax({
						type: "PUT",
						url:"http://127.0.0.1/api/contacts/insert", 
						headers:{"authorization":authorization},
						contentType : 'application/json',
						dataType : 'json',
						type: "POST",
						data:JSON.stringify({'list':[{'name':'测试'},{'name':'测试二'}]}),
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				getUser:function(current){
					demo.ajax("http://127.0.0.1/api/user?username="+current,function(data){
						demo.display(data) ;
						
					});
				},
				getExtention:function(){
					demo.ajax("http://127.0.0.1/api/extention");
				},
				qualityList:function(){
					demo.ajax("http://127.0.0.1/api/quality");
				},
				leavemsgList:function(){
					demo.ajax("http://127.0.0.1/api/leavemsg");
				},
				topicList:function(){
					demo.ajax("http://127.0.0.1/api/xiaoe/topic");
				},
				chatMsgList:function(){
					demo.ajax("http://127.0.0.1/api/chatmessage?serviceid=4028b46f62d309c10162d30e7fcd0366");
				},
				callcenterevent:function(){
					demo.ajax("http://127.0.0.1/api/callcenter/search");
				},
				voicerecord:function(){
					demo.ajax("http://127.0.0.1/api/callcenter/voice/cd884801-53b5-48d3-b5aa-b44f56235cec");
				},
				agentStatus:function(){
					var param = 'status=ready';
					$.ajax({
						type: "PUT",
						url:"http://127.0.0.1/api/servicequene" ,
						data: param,
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				getsession:function(){
					$.ajax({
						type: "POST",
						url:"http://127.0.0.1/session" ,
						data: {userid:'999'},
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				msgshoplist:function(){
					$.ajax({
						type: "POST",
						url:"http://127.0.0.1/api/webim/msg/shoplist" ,
						data: {userid:'999'},
						beforeSend: function(xhr) {
							xhr.setRequestHeader("authorization", authorization);

						},
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				msgshoplist2:function(){
					$.ajax({
						type: "POST",
						url:"http://127.0.0.1/api/webim/msg/shoplist" ,
						data: {userid:'999',shopname:'京东'},
						beforeSend: function(xhr) {
							xhr.setRequestHeader("authorization", authorization);

						},
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				unreadcount:function(){
					$.ajax({
						type: "POST",
						url:"http://127.0.0.1/api/webim/msg/unreadcount" ,
						data: {userid:'999'},
						beforeSend: function(xhr) {
							xhr.setRequestHeader("authorization", authorization);

						},
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				resetunreadcount:function(){
					$.ajax({
						type: "POST",
						url:"http://127.0.0.1/api/webim/msg/resetunreadcount" ,
						data: {userid:'999',orgi:'bf68b43d695746fcad9b2cd341c8c39b'},
						beforeSend: function(xhr) {
							xhr.setRequestHeader("authorization", authorization);

						},
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				chathis:function(){
					$.ajax({
						type: "POST",
						url:"http://127.0.0.1/api/webim/chat/his" ,
						data: {userid:'999',uid:'c1fbca8db14b95ba2478f0757329a6b2',orgi:'bf68b43d695746fcad9b2cd341c8c39b'},
						beforeSend: function(xhr) {
							xhr.setRequestHeader("authorization", authorization);

						},
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				sendproduct:function(){
					var datasend = {
						userid:"999",
						orgi:"bf68b43d695746fcad9b2cd341c8c39b",
						appid:"1tFBUZ",
						producturl:encodeURIComponent("https://item.jd.com/44069227301.html"),
						producttitle:"华为P30手机 【白条6期免息0首付+20天价保+现货当天发+1年碎屏险】 亮黑色 全网通 8G+128G(6期免息)",
						productlogo:encodeURIComponent("http://img11.360buyimg.com/n1/s450x450_jfs/t1/37515/18/9675/730836/5ccfa4edE567b64d9/1041d879cbe8d7dc.png"),
						productid:"44069227301",
						productprice:"￥3958.00"
					}
					var sendProduct = function(){
						$.ajax({
							type : 'POST',
							url: "http://127.0.0.1/api/webim/product/send",
							data : datasend,
							beforeSend: function(xhr) {
								xhr.setRequestHeader("authorization", authorization);

							},
							success : function(res) {
								if(typeof data == 'string'){
									value = data ;
								}else{
									value = JSON.stringify(data)
								}
								layer.open({
								  type: 1,
								  area: ['800px', '500px'],
								  content: "<div style='width:100%;height:100%;overflow:hidden;'><textarea style='width:100%;height:100%;' readOnly='readOnly'>"+value+"</textarea></div>" //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
								});
							},
							error : function() {
								layer.alert("系统错误", {icon: 2});
							}
						});
					}
					sendProduct();
				},
				getweblist:function(){
					$.ajax({
						type: "POST",
						url:"http://127.0.0.1/api/webim/getweblist" ,
						data: {userid:'999',orgi:'bf68b43d695746fcad9b2cd341c8c39b'},
						beforeSend: function(xhr) {
							xhr.setRequestHeader("authorization", authorization);

						},
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				getuserlist:function(){
					$.ajax({
						type: "GET",
						url:"http://127.0.0.1/api/user" ,
						data: {p:1,ps:2},
						beforeSend: function(xhr) {
							xhr.setRequestHeader("authorization", authorization);

						},
						success: function (data) {
							demo.display(data) ;
						}
					});
				},
				getorganlist:function(){
					$.ajax({
						type: "GET",
						url:"http://127.0.0.1/api/organ" ,
						data: {p:1,ps:2},
						beforeSend: function(xhr) {
							xhr.setRequestHeader("authorization", authorization);

						},
						success: function (data) {
							demo.display(data) ;
						}
					});
				}
			}
			$(document).ready(function(){
				demo.login();
			});
		</script>
	</head>
    
    <body>
		<table class="layui-table">
			<tr>	
				<th>获取当前登录用户信息</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.getUser('admin')">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>创建工单</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.createWorkOrder()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>批量创建联系人</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.createContacts()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>批量添加名单</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.createNamesList()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>查询名单</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.searchNamesList()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取质检列表</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.qualityList()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取分机信息</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.getExtention()">调用测试</a>
				</th>
			</tr>


			<tr>	
				<th>获取留言列表</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.leavemsgList()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取对话内容列表</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.chatMsgList()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取知识库列表</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.topicList()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>坐席状态</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.agentStatus()">调用测试</a>
				</th>
			</tr>


			<tr>	
				<th>通话历史</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.callcenterevent()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>通话历史</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.callcenterevent()">调用测试</a>
				</th>
			</tr>


			<tr>	
				<th>getsession</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.callcenterevent()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取某个用户当前聊天店铺列表</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.msgshoplist()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取某个用户当前聊天店铺列表（店铺名模糊搜索）</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.msgshoplist2()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取某个用户当前未读消息总数</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.unreadcount()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>清空某个用户当前未读消息数</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.resetunreadcount()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>某个会话历史</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.chathis()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>发送商品消息</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.sendproduct()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取租户IM网站列表配置</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.getweblist()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取用户列表配置</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.getuserlist()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>获取部门列表配置</th>
				<th>
					<a href="javascript:void(0)" onclick="demo.getorganlist()">调用测试</a>
				</th>
			</tr>

			<tr>	
				<th>通话历史</th>
				<th>
					<a href="javascript:void(0)" target="_blank" onclick="window.open('http://127.0.0.1/api/callcenter/voice/cd884801-53b5-48d3-b5aa-b44f56235cec?authorization='+authorization)">调用测试</a>
				</th>
			</tr>

		<div id="temp"></div>


	</body>

</html>